package org.example.aaaatest.jsonString;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.example.aaaatest.money.CurrencyConversion;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @description:
 * @author: wangbaogui
 * @create: 2025/2/27 13:32
 **/

public class bbb {
    public static void main(String[] args) throws JsonProcessingException {


        BodLanguageDetail bodLanguageDetail = new BodLanguageDetail();
        bodLanguageDetail.setFirstAbuseRole("sss");
        List<Map<String, String>> arrayList = new ArrayList<>();
        HashMap<String, String> map = new HashMap<>();
        map.put("呢大衣", "你大爷");
        arrayList.add(map);
        bodLanguageDetail.setUserAbuseWordsSentenceDetail(arrayList);
        bodLanguageDetail.setDriverAbuseWordsCount(1);
         Map<String, Integer> map1 = new HashMap<>();
         map1.put("你大爷", 1);
        bodLanguageDetail.setDriverAbuseWordsCountDetail(map1);
        bodLanguageDetail.setUserAbuseWordsCount(1);
        bodLanguageDetail.setUserAbuseWordsCountDetail(map1);
        bodLanguageDetail.setDriverAbuseWordsSentenceDetail(arrayList);
        bodLanguageDetail.setCurrencyConversion(new CurrencyConversion());
       System.out.println("bodLanguageDetail = " + bodLanguageDetail);

        JSONObject currencyConversion = JSONObject.parseObject(JSON.toJSONString(bodLanguageDetail)).getJSONObject("currencyConversion");
        System.out.println("currencyConversion = " + JSON.toJSONString(currencyConversion));

        if((Objects.nonNull(currencyConversion) && !currencyConversion.isEmpty())){
            System.out.println("currencyConversion ======================= " + currencyConversion);
        }


        System.out.println("============================================================");
        Object json = JSON.toJSON(bodLanguageDetail);
      //  System.out.println("json = " + json);

        System.out.println("============================================================");

        String a = "{\"status\":\"ok\",\"message\":\"\",\"data\":{\"amap_order_id\":\"222\",\"cp_amap_order_id\":\"3333\",\"driver_unique_id\":\"default\",\"cp_order_id\":\"null\",\"user_id\":\"574280533\",\"predict_score\":{\"abuse_score\":0.5},\"request_time\":1.014892578125,\"feature_time\":0,\"model_time\":" +
                "0.954833984375,\"detail\":{\"first_abuse_role\":\"driver\",\"driver_abuse_words_count\":2,\"driver_abuse_words_count_detail\":{\"你大爷\":1,\"妈了个\":1}" +
                ",\"driver_abuse_words_sentence_detail\":[{\"你大爷\":\"喂能听到吗 你奶奶个腿 时长那人确实有点不太够 我去你大爷的，妈了个巴的\"}," +
                "{\"妈了个\":\"喂能听到吗 你奶奶个腿 时长那人确实有点不太够 我去你大爷的，妈了个巴的\"}],\"user_abuse_words_count\"" +
                ":2,\"user_abuse_words_count_detail\":{\"你大爷\":1,\"妈了个\":1},\"user_abuse_words_sentence_detail\"" +
                ":[{\"你大爷\":\"乘客给司机拨打电话测试，语音骂人 我去你大爷的，你妈了个巴\"},{\"妈了个\":\"乘客给司机拨打电话测试，语音骂人 我去你大爷的，你妈了个巴\"}]},\"feature\":{}}}";



        ObjectMapper objectMapper = new ObjectMapper();
        BodLanguageDetailResponse bodLanguageDetailResponse1 = objectMapper.readValue(a, BodLanguageDetailResponse.class);
        System.out.println("bodLanguageDetailResponse =========== " + bodLanguageDetailResponse1);
        /**
         * json字符串转实体类用@JsonProperty("amap_order_id")
         *
         * objectMapper1.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
         * 这个是全局的配置 @JsonProperty
         */

        Object json1 = JSON.toJSON(bodLanguageDetail);
        /**
         * 实体类转json用 @JSONField(name = "first_abuse_role")
         */
        System.out.println("json1 ==================== " + json1);
    }
}
